public class Class {


    public int strStr(String haystack, String needle) {
        int  l1=0;
        for (int l2 = 0; l2 <haystack.length() ; ) {
            if (l1==needle.length()-1&&haystack.charAt(l2)==needle.charAt(l1)){
                return l2-needle.length()+1;
            }
            if (haystack.charAt(l2)==needle.charAt(l1)){
                l1++;
                l2++;
            }else {
                l1=0;
//                l2++;
            }
        }
        return   -1;
    }


    public int strStr1(String haystack, String needle) {
        int l = 0,r = 0;
        while(r <= needle.length()-1 && l <= haystack.length()-1){
            while(r <= needle.length()-1 && l <= haystack.length()-1 && needle.charAt(r) == haystack.charAt(l)){
                r++;
                if(r == needle.length()){
                    return l-r+1;
                }
                l++;
            }
            if(r == 0){
                l++;
            }else if(r != 0 ){
                l = l-r+1;
                r = 0;
            }

        }
        return -1;
    }



    public static void main(String[] args) {
        Class aClass = new Class();
        int i = aClass.strStr("hello", "ll");
        System.out.println(i);
    }
}
